$(function () {
    function getPageAdvert(placeKey) {
       var urls = opWebPath+'/web/op/ajax/queryAdvert?placeKey='+placeKey;
       $.ajax({
           url: urls,
           type: "post",
           dataType: "jsonp",
           jsonp: "callback", //服务端用于接收callback调用的function名的参数
           jsonpCallback: "get_advert_callback", //callback的function名称,服务端会把名称和data一起传递回来
           success: function(json) {
               if(json.success==true){
                   var entity = json.entity;
                   if(entity!=null && entity.imageMap!=null){
                       var imageMap = entity.imageMap;
                       var url = imageMap.url;
                       var redirectUrl = '';
                       if(entity.redirectType==2){
                            redirectUrl = courseWebPath + '/web/course/info?courseId='+entity.courseId;
                       }else{
                            redirectUrl = entity.pageUrl;
                       }
                       var em = $("#advert-list-context-box-img");
                       em.attr('href',redirectUrl);
                       em.find('img').attr('src',url);
                       var newPage = entity.newPage;
                       if(newPage==2){
                           em.attr('target','_blank');
                       }
                       $("#advert-list-context-box-img-parent").removeClass("hide");
                   }
               }
           },
           error: function(error){
               console.info("-----获取广告数据错误");
           }
       });
    }
    var _emlist = $("#advert-list-context-box-img");
    if(_emlist!=null && typeof _emlist !='undefined'){
        var placeKey = _emlist.data('place-key');
        if(placeKey!=null && $.trim(placeKey)!=''){
            getPageAdvert(placeKey);
        }
    }
});